/*
 * This file is part of Visual Keyboard Navi software
 *
 * Copyright (C) 2014 Denis Kvita <dkvita@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include <QFileSystemModel>
#include <QTreeView>
#include <QGridLayout>
#include <QToolBar>
#include <QTextEdit>
#include <QLabel>
#include <QLineEdit>
#include <QFrame>

#include "widget.h"

// add visual keyboard navigation
#include "visualKeyboardNavi/visualkeyboardnavigator.h"

Widget::Widget(QWidget *parent)
    : QMainWindow(parent)
{
    setWindowTitle(tr("Press 'Ctrl+Tab' and then labeled key"));
    QGridLayout *lt= new QGridLayout();

    QFileSystemModel *mdl= new QFileSystemModel(this);
    mdl->setRootPath("d:");
    QTreeView *tv= new QTreeView(this);
    tv->setModel(mdl);
    lt->addWidget(tv,0,0,1,2);
    //register widget to be navigable through 'Ctrl+Tab,1'
    VisualKeyboardNavigator::registerTag(Qt::Key_1, new VisualTag("1",this),tv);

    QFrame *leftFrm= new QFrame();
    leftFrm->setFrameStyle(QFrame::Raised|QFrame::WinPanel);
    VisualKeyboardNavigator::registerTag(Qt::Key_2, new VisualTag("2",this),leftFrm);
    KeyPath context= KeyPath()<<Qt::Key_2;

    QGridLayout *leftFrmLt= new QGridLayout();
    leftFrmLt->addWidget(new QLabel(tr("field 1")),0,0);
    QLineEdit *edt= new QLineEdit();
    leftFrm->setFocusProxy(edt);
    //register widget to be navigable through 'Ctrl+Tab,1,1'
    VisualKeyboardNavigator::registerTag(context, Qt::Key_1, new VisualTag("1",this),edt);
    leftFrmLt->addWidget(edt,0,1);
    leftFrmLt->addWidget(new QLabel(tr("field 2")),1,0);
    edt= new QLineEdit();
    VisualKeyboardNavigator::registerTag(context, Qt::Key_2, new VisualTag("2",this),edt);
    leftFrmLt->addWidget(edt,1,1);

    leftFrmLt->addWidget(new QLabel(tr("field 3")),2,0);
    edt= new QLineEdit();
    VisualKeyboardNavigator::registerTag(context, Qt::Key_3, new VisualTag("3",this),edt);
    leftFrmLt->addWidget(edt,2,1);

    leftFrmLt->addWidget(new QLabel(tr("field 4")),3,0);
    edt= new QLineEdit();
    VisualKeyboardNavigator::registerTag(context, Qt::Key_4, new VisualTag("4",this),edt);
    leftFrmLt->addWidget(edt,3,1);

    leftFrmLt->addWidget(new QLabel(tr("field 5")),4,0);
    edt= new QLineEdit();
    VisualKeyboardNavigator::registerTag(context, Qt::Key_5, new VisualTag("5",this),edt);
    leftFrmLt->addWidget(edt,4,1);
    leftFrmLt->setRowStretch(5,1);

    leftFrm->setLayout(leftFrmLt);
    lt->addWidget(leftFrm,1,0);

    // right frame
    QFrame *rightFrm= new QFrame();
    rightFrm->setFrameStyle(QFrame::Raised|QFrame::WinPanel);
    VisualKeyboardNavigator::registerTag(Qt::Key_3, new VisualTag("3",this),rightFrm);
    context= KeyPath()<<Qt::Key_3;

    QGridLayout *rightFrmLt= new QGridLayout();
    rightFrmLt->addWidget(new QLabel(tr("field 1")),0,0);
    edt= new QLineEdit();
    rightFrm->setFocusProxy(edt);
    VisualKeyboardNavigator::registerTag(context, Qt::Key_1, new VisualTag("1",this),edt);
    rightFrmLt->addWidget(edt,0,1);
    rightFrmLt->addWidget(new QLabel(tr("field 2")),1,0);
    edt= new QLineEdit();
    VisualKeyboardNavigator::registerTag(context, Qt::Key_2, new VisualTag("2",this),edt);
    rightFrmLt->addWidget(edt,1,1);

    rightFrmLt->addWidget(new QLabel(tr("field 3")),2,0);
    edt= new QLineEdit();
    VisualKeyboardNavigator::registerTag(context, Qt::Key_3, new VisualTag("3",this),edt);
    rightFrmLt->addWidget(edt,2,1);

    rightFrmLt->addWidget(new QLabel(tr("field 4")),3,0);
    edt= new QLineEdit();
    VisualKeyboardNavigator::registerTag(context, Qt::Key_4, new VisualTag("4",this),edt);
    rightFrmLt->addWidget(edt,3,1);

    rightFrmLt->addWidget(new QLabel(tr("field 5")),4,0);
    edt= new QLineEdit();
    VisualKeyboardNavigator::registerTag(context, Qt::Key_5, new VisualTag("5",this),edt);
    rightFrmLt->addWidget(edt,4,1);

    rightFrmLt->addWidget(new QLabel(tr("field 6")),5,0);
    edt= new QLineEdit();
    VisualKeyboardNavigator::registerTag(context, Qt::Key_6, new VisualTag("6",this),edt);
    rightFrmLt->addWidget(edt,5,1);

    rightFrmLt->setRowStretch(6,1);
    rightFrm->setLayout(rightFrmLt);
    lt->addWidget(rightFrm,1,1);

    QTextEdit *te= new QTextEdit(this);
    te->setText("Editable text.");
    lt->addWidget(te,0,3);
    //register widget to be navigable through 'Ctrl+Tab,4'
    VisualKeyboardNavigator::registerTag(Qt::Key_4, new VisualTag("4",this),te);

    te= new QTextEdit(this);
    te->setText("Another editable text.");
    lt->addWidget(te,1,3);
    //register widget to be navigable through 'Ctrl+Tab,5'
    VisualKeyboardNavigator::registerTag(Qt::Key_5, new VisualTag("5",this),te);

    QWidget *mainWidget= new QWidget();
    mainWidget->setLayout(lt);

    setCentralWidget(mainWidget);
}

Widget::~Widget()
{
    ;
}
